package com.app.service.Impl;

import com.app.mapper.MotionVideoMapper;
import com.app.model.MotionVideoModel;
import com.app.service.MotionVideoService;
import com.app.vo.VideoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MotionVideoServiceImpl implements MotionVideoService {
    @Autowired
    private MotionVideoMapper motionVideoMapper;

    @Override
    public void update(MotionVideoModel model) {
        motionVideoMapper.updateById(model);
    }

    @Override
    public void insert(MotionVideoModel model) {
        motionVideoMapper.insert(model);
    }

    @Override
    public void deleteById(Integer id) {
        motionVideoMapper.deleteById(id);
    }

    @Override
    public VideoVo selectList(Integer page, Integer limit, String keyword, Integer type) {
        VideoVo vo = new VideoVo();
        page = (page - 1) * limit;
        List<MotionVideoModel> videoModelList = motionVideoMapper.getVideoList(page, limit, keyword, type);
        for (int i = 0; i < videoModelList.size(); i++) {
            if (videoModelList.get(i).getType() != null && videoModelList.get(i).getType() == 1) {
                videoModelList.get(i).setTypeText("视频");
            } else if (videoModelList.get(i).getType() != null && videoModelList.get(i).getType() == 2) {
                videoModelList.get(i).setTypeText("图文");
            }
        }
        int count = motionVideoMapper.getVideoCount(keyword, type);
        vo.setList(videoModelList);
        vo.setCount(count);
        return vo;
    }

    @Override
    public VideoVo getList(Integer page, Integer limit, String keyword, Integer type) {
        VideoVo vo = new VideoVo();
        page = (page - 1) * limit;
        List<MotionVideoModel> videoModelList = motionVideoMapper.selectVideoList(page, limit, keyword, type);
        int count = motionVideoMapper.selectVideoCount(keyword, type);
        vo.setList(videoModelList);
        vo.setCount(count);
        return vo;
    }

    @Override
    public MotionVideoModel selectById(Integer id) {
        return motionVideoMapper.selectById(id);
    }
}
